﻿@{
    Layout = "~/Views/Shared/_FormWhite.cshtml";
}
@inject Microsoft.AspNetCore.Hosting.IWebHostEnvironment HostingEnvironment
@section header{
<link href="@Url.Content("~/lib/summernote/0.8.15/summernote.min.css")" rel="stylesheet" type="text/css">
<script src='@Url.Content("~/lib/summernote/0.8.15/summernote.js")' type="text/javascript"></script>
<script src='@Url.Content("~/lib/summernote/0.8.15/lang/summernote-zh-CN.min.js")' type="text/javascript"></script>

    @BundlerHelper.Render(HostingEnvironment.ContentRootPath, Url.Content("~/lib/imageupload/1.0/css/imgup.min.css"))
    @BundlerHelper.Render(HostingEnvironment.ContentRootPath, Url.Content("~/lib/imageupload/1.0/js/imgup.min.js"))

    @BundlerHelper.Render(HostingEnvironment.ContentRootPath, Url.Content("~/lib/bootstrap.tagsinput/0.8.0/bootstrap-tagsinput.min.css"))
    @BundlerHelper.Render(HostingEnvironment.ContentRootPath, Url.Content("~/lib/bootstrap.tagsinput/0.8.0/bootstrap-tagsinput.min.js"))

}
<div class="wrapper animated fadeInRight">
    <form id="form" class="form-horizontal m">
        <div class="form-group">
            <label class="col-sm-2 control-label">姓名<font class="red"> *</font></label>
            <div class="col-sm-10">
                <input id="name" col="Name" type="text" class="form-control" />
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label">电话</label>
            <div class="col-sm-10">
                <input id="tel" col="Tel" type="text" class="form-control" />
            </div>
        </div>

        <div class="form-group">
            <label class='col-sm-2 control-label'>城市</label>
            <div class="col-sm-10">
                <div id="cityCode" col="CityCode"></div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label ">用户<font class="red"> *</font></label>
            <div class="col-sm-10" id="userId" col="UserId"></div>
        </div>

        <div class="form-group">
            <label class="col-sm-2 control-label">创建时间</label>
            <div class="col-sm-10 ">
                <input type="text" id="setTime" col="SetTime" class="form-control">
            </div>
        </div>
    </form>
</div>

<script type="text/javascript">
     var id = ys.request("id");
     $(function () {

         ys.ajax({
                  url: '@Url.Content("~/RedBookFormManage/RedBookFormList/GetUserDataJson")',
                 type: "get",
                 async:false,
                 success: function (obj) {
                     if (obj.Tag == 1) {
                         var result = obj.Data;
                           $("#userId").ysComboBox({
                                       data: result,
                                       class: "form-control"
                                    });
                     }
                 }
         });

          loadMenuTree();
             getForm();

          laydate.render({
                    elem: '#setTime'
                    ,trigger:'click'
                    ,position:'fixed'
                    ,format: 'yyyy-MM-dd'
                 });
      });

    function loadMenuTree() {
         $('#cityCode').ysComboBoxTree({
             url: '@Url.Content("~/RedBookSetManage/RedBookSet/GetFormAreaJson")',
             expandLevel: 0
         })
     }

     function getForm() {
         if (id > 0) {
             ys.ajax({
                 url: '@Url.Content("~/RedBookFormManage/RedBookFormList/GetFormJson")' + '?id=' + id,
                 type: "get",
                 async:false,
                 success: function (obj) {
                     if (obj.Tag == 1) {
                         var result = obj.Data;
                         //result.UserId=result.UserId.toString();
                         $("#form").setWebControls(result);
                        // $("#area").ysTree("setCheckedNodes", obj.Data.Area);

                     }
                 }
             });
         }
     }

     function saveForm(index) {
         if ($("#form").validate().form()) {
             var postData = $("#form").getWebControls({ Id: id });
             postData.City=$('#cityCode').attr("data-value");
             if(postData.UserId=="" || postData.UserId==null ||postData.UserId==undefined)
             {
                 layer.alert("请选择用户！",{icon: 5});
                  return ;
             }
             ys.ajax({
                 url: '@Url.Content("~/RedBookFormManage/RedBookFormList/SaveFormJson")',
                 type: "post",
                 data: postData,
                 success: function (obj) {
                     if (obj.Tag == 1) {
                         ys.msgSuccess(obj.Message);
                         parent.searchGrid();
                         parent.layer.close(index);
                     }
                     else {
                         ys.msgError(obj.Message);
                     }
                 }
             });
         }
     }

</script>

